﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace weba
{
    public partial class upldpic : System.Web.UI.Page
    {
        sjklqDataContext sj = new sjklqDataContext();
        public static List<pics> o = new List<pics>();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            List<pics> ps = new List<pics>();
            string path = Server.MapPath("Images");
            //获取文件夹中所有图片  
            if (Directory.GetFileSystemEntries(path).Length > 0)
            {
                //遍历文件夹中所有文件  
                foreach (string file in Directory.GetFiles(path))
                {
                    //文件己存在  
                    if (File.Exists(file))
                    {
                        FileInfo fi = new FileInfo(file);
                        //判断当前文件属性是否是只读  
                        string s = fi.Name;
                        pics p = new pics() { picurl=s};
                        //删除文件  
                        ps.Add(p);

                    }
                }
            }
             o = (from a in ps where !(from b in sj.pics.ToList() select b.picurl).Contains(a.picurl) select a).ToList();
            dst1.DataSource = o;
            dst1.DataBind();

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            foreach (pics n in o)
            {
                sj.pics.InsertOnSubmit(n);
            }
            sj.SubmitChanges();
        }
    }
}